package com.neusoft.a312cxy.android18cxy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.neusoft.a312cxy.android18cxy.Listener.PostListener;
import com.neusoft.a312cxy.android18cxy.R;
import com.neusoft.a312cxy.android18cxy.model.MySelfModel;
import com.squareup.picasso.Picasso;

/**
 * Created by Young on 2017/10/26.
 */

public class EditpersonActivity extends AppCompatActivity {
    private EditText name1,intro,telephone;
    private String sex;
    private Button querenBtn;
    private ImageView photo;
    private String photo1;
    private String id;
    private String userid,name;
    private RadioGroup radiogroupsex;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_editperson);
        initView();
        saveDate();
       // getuserinfo;
}

    private void initView() {
        name1=(EditText)findViewById(R.id.Name);
        intro=(EditText)findViewById(R.id.intro);
        telephone=(EditText)findViewById(R.id.telephone);
       // sex=(EditText)findViewById(R.id.sex);
        radiogroupsex=(RadioGroup)findViewById(R.id.radiogroupsex) ;
        querenBtn=(Button)findViewById(R.id.queren);
        photo=(ImageView)findViewById(R.id.photo);

        querenBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Toast.makeText(EditpersonActivity.this, telephone.getText().toString(), Toast.LENGTH_SHORT).show();
                MySelfModel mySelfModel = new MySelfModel();
                mySelfModel.editTel("19",telephone.getText().toString(),name1.getText().toString(),sex,intro.getText().toString(),postedittel );
            //    mySelfModel.editName("2",name1.getText().toString(),posteditname );
                //  edt.getText().toString().trim()
          //     Toast.makeText(EditpersonActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
            //    saveDate();

            }


        });
        radiogroupsex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
                switch (i){
                    case R.id.nan:
                        sex="男";
                        break;
                    case R.id.nv:
                        sex="女";
                        break;
                }
            }
        });

    }

    public void saveDate(){
        Intent intent = getIntent();

        photo1=intent.getStringExtra("photo");
        if(photo1!=null){
            Picasso.with(this).load("http://172.24.10.175/workout/Uploads/"+photo1).into(photo);
        }
        else {
            photo.setImageResource(R.drawable.i5);
        }
        telephone.setText(intent.getStringExtra("tel"));
    //    sex.setText(intent.getStringExtra("sex"));
        intro.setText(intent.getStringExtra("intro"));
        name1.setText(intent.getStringExtra("name"));



    }

    PostListener<String> postedittel=new PostListener<String>() {
        @Override
        public void onResponse(String post) {
            if (post.equals("1")){
                Toast.makeText(EditpersonActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(EditpersonActivity.this,MainActivity.class);
             //   intent.putExtra( "id" , 4);
                startActivity(intent);
                finish();
            }else {
                Toast.makeText(EditpersonActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(EditpersonActivity.this, "ONFAIL修改失败", Toast.LENGTH_SHORT).show();
        }
    };

/*    PostListener<String> posteditname=new PostListener<String>() {
        @Override
        public void onResponse(String post) {
            if (post.equals("1")){
                Toast.makeText(EditpersonActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
               // finish();
            }else {
                Toast.makeText(EditpersonActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(EditpersonActivity.this, "ONFAIL修改失败", Toast.LENGTH_SHORT).show();
        }
    };*/


}
